<?php

class CartTempRecord extends TActiveRecord
{
	const TABLE='tbl_cart_temp';

	public $SessionID;
	public $UserID=0;
	public $BillingID=0;
	public $ShippingID=0;
	public $Subtotal=0;
	public $ShippingMethodID=0;
	public $ShippingAmount=0;
	public $CouponCode=0;
	public $CouponAmount=0;
	public $TaxAmount=0;
	public $RewardPointsRebate=0;
	public $Total=0;
	public $EstDeliveryDate;
	public $CreateDate=0;
	
	public static $COLUMN_MAPPING=array
	(
		'session_id'=>'SessionID',
		'user_id'=>'UserID',
		'billing_id'=>'BillingID',
		'shipping_id'=>'ShippingID',
		'subtotal'=>'Subtotal',
		'shipping_method_id'=>'ShippingMethodID',
		'shipping_amount'=>'ShippingAmount',
		'coupon_code'=>'CouponCode',
		'coupon_amount'=>'CouponAmount',
		'tax_amount'=>'TaxAmount',
		'reward_points_rebate'=>'RewardPointsRebate',
		'total'=>'Total',
		'est_delivery_date'=>'EstDeliveryDate',
		'c_date'=>'CreateDate'
	);
	
	public static function finder($className=__CLASS__)
	{
		return parent::finder($className);
	}
	
	public function getSubtotalInSession()
	{
		//$activeRecord = self::finder()->withCartTempDetails()->findByPk(Prado::getApplication()->Session->SessionID);
		$items = CartTempDetailRecord::finder()->findAllBysession_id(Prado::getApplication()->Session->SessionID);
		$subtotal = 0;
		
		foreach($items as $item)
		{
			$subtotal += $item->Subtotal;
		}
		
		return $subtotal;
	}
}
?>